<?php
header('Content-Type: application/json');

$dataFile = '../../data/heroes.json';

try {
    if (!file_exists($dataFile)) {
        file_put_contents($dataFile, json_encode(['heroes' => [], 'next_id' => 1]));
    }
    
    $data = json_decode(file_get_contents($dataFile), true);
    echo json_encode(['success' => true, 'data' => $data['heroes']]);
    
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
?> 